﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AutoGetFoodAndGoldDragonTool
{
    public partial class frmMain : Form
    {
        public string FBID;
        public string UserKey;
        public bool UserkeyIsNull = true;
        public int BienFistLike = 1;
        public string HabitatFood = "-1";
        public string HabitatGold = "-1";
        public int NumRepeat = 0;
        public int NumTimeDelay = 0;
        public int TotalCount = 0;
        string SignedRequest = "";
        //public int SoLanVong;
        public Thread TheadOne;

        bool flagStop = false;

        public frmMain()
        {
            InitializeComponent();
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            if (this.TheadOne != null)
            {
                this.TheadOne.Abort();
            }

            //ref Init
            flagStop = true;
            this.progressBar1.Value = 0;
            this.lblThead1Percentage.Text = "--:--";
            this.progressBar2.Value = 0;
            this.lblThead2Percentage.Text = "--:--";
            this.progressBar3.Value = 0;
            this.lblThead3Percentage.Text = "--:--";
            this.lblMsg.Text = "";
            this.btnStart.Show();
            NumRepeat = 0;
            NumTimeDelay = 0;
            TotalCount = 0;
            FBID = "";
            UserKey = "";
            UserkeyIsNull = true;
            this.lblCount.Text = "0";
            BienFistLike = 1;
            HabitatFood = "-1";
            HabitatGold = "-1";
        
        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.TheadOne != null)
            {
                this.TheadOne.Abort();
            }
            Application.Exit();
        }


        private void FuntionRoot()
        {
            while (!flagStop)
            {
                //sleep 
                if (NumRepeat == int.Parse(this.lblCount.Text))
                {
                    Thread.Sleep(NumTimeDelay*60*1000);
                }

                this.progressBar3.Value = 0;

                //this.lblThead3Percentage.Text = "0%";
                UpdateText(lblThead3Percentage, "0%");

                this.BienFistLike = 1;
                this.HamMain();
                this.ExportInformationUser();
                Thread.Sleep(10000);
                this.progressBar1.Value = 0;
                this.lblThead1Percentage.Text = "--:--";
                this.progressBar2.Value = 0;
                this.lblThead2Percentage.Text = "--:--";
                this.progressBar3.Value = 0;
                
                //this.lblThead3Percentage.Text = "--:--";
                UpdateText(lblThead3Percentage, "--:--");
                
                TotalCount += int.Parse(this.lblCount.Text);
                lblTotalCount.Text = TotalCount.ToString();
            }

            MessageBox.Show("Hacked", "Message", MessageBoxButtons.OK, MessageBoxIcon.None);
            this.progressBar3.Value = 0;
            
            //this.lblThead3Percentage.Text = "--:--";
            UpdateText(lblThead3Percentage, "--:--");

            this.lblMsg.Text = "--:--";
            this.btnStart.Show();
        }

        private void UpdateText(Label label, string text)
        {
            // If the current thread is not the UI thread, InvokeRequired will be true
            if (label.InvokeRequired)
            {
                // If so, call Invoke, passing it a lambda expression which calls
                // UpdateText with the same label and text, but on the UI thread instead.
                label.Invoke((Action)(() => UpdateText(label, text)));
                return;
            }
            // If we're running on the UI thread, we'll get here, and can safely update 
            // the label's text.
            label.Text = text;
        }

        private string GetText(RichTextBox richText)
        {
            // If the current thread is not the UI thread, InvokeRequired will be true
            if (richText.InvokeRequired)
            {
                // If so, call Invoke, passing it a lambda expression which calls
                // UpdateText with the same label and text, but on the UI thread instead.
                richText.Invoke((Action)(() => GetText(richText)));
                return "";
            }
            // If we're running on the UI thread, we'll get here, and can safely update 
            // the label's text.
            return richText.Text;
        }

        private void ShowHideControl(Button btnControl, bool isShow)
        {
            // If the current thread is not the UI thread, InvokeRequired will be true
            if (btnControl.InvokeRequired)
            {
                // If so, call Invoke, passing it a lambda expression which calls
                // UpdateText with the same label and text, but on the UI thread instead.
                btnControl.Invoke((Action)(() => ShowHideControl(btnControl, isShow)));
                return;
            }
            // If we're running on the UI thread, we'll get here, and can safely update 
            // the label's text.
            if (isShow)
                btnControl.Show();
            else
                btnControl.Hide();
        }
        private string GetIDitemFarm(string t, int LoaiFarm)
        {
            int index = t.IndexOf("\"map\"");
            int tim = t.IndexOf("\"items\":{", index);
            if (tim <= -1)
            {
                MessageBox.Show("Selecting the appropriate farm!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.btnStart.Show();
                this.TheadOne.Abort();
                return null;
            }
            int num3 = this.FindFarm(t, LoaiFarm, tim);
            if (num3 == -1)
            {
                MessageBox.Show(" You don't have farm for hack!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                this.TheadOne.Abort();
            }
            int num4 = num3;
            int num5 = 1;
            int num6 = -1;
            while (true)
            {
                if (t[num4] == '"')
                {
                    if (num5 == 1)
                    {
                        num5--;
                    }
                    else
                    {
                        num6 = num4 + 1;
                        break;
                    }
                }
                num4--;
            }
            string str = null;
            for (int i = num6; i < t.Length; i++)
            {
                if (t[i] == '"')
                {
                    return str;
                }
                str = str + t[i];
            }
            return str;
        }

        private bool GetIdUserKey()
        {
            try
            {
                this.FBID = null;
                this.UserKey = null;
                string requestUriString = "http://dc-canvas.socialpointgames.com/dragoncity/web/fb/?fb_source=bookmark_apps&ref=bookmarks&count=33&fb_bmpos=4_33";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUriString);
                request.Method = "POST";
                request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ProtocolVersion = HttpVersion.Version11;
                request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                request.KeepAlive = false;
                request.Timeout = 0x493e0;
                request.Proxy = null;
                request.Credentials = CredentialCache.DefaultCredentials;
                //string str2 = "signed_request=" + this.txtSignedRequest.Text + "&locale=vi_VN";
                string str2 = "signed_request=" + SignedRequest + "&locale=vi_VN";
                StreamWriter writer = new StreamWriter(request.GetRequestStream());
                writer.Write(str2);
                writer.Close();
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                string str3 = new StreamReader(response.GetResponseStream()).ReadToEnd();
                int index = str3.IndexOf("userId = ");
                if (index == -1)
                {
                    return false;
                }
                for (int i = index + 10; i < str3.Length; i++)
                {
                    if (str3[i] == '"')
                    {
                        break;
                    }
                    this.FBID = this.FBID + str3[i];
                }
                int num3 = str3.IndexOf("sessionId");
                if (num3 == -1)
                {
                    return false;
                }
                for (int j = num3 + 11; j < str3.Length; j++)
                {
                    if (str3[j] == ',')
                    {
                        break;
                    }
                    this.UserKey = this.UserKey + str3[j];
                }
                return true;
            }
            catch(Exception ex)
            {
                return false;
            }
        }

        private void HamMain()
        {
            int num = int.Parse(this.txtRepeat.Text);
            this.lblCount.Text = "0";
            for (int i = 0; i < num; i++)
            {
                if (this.UserkeyIsNull)
                {
                    if (this.GetIdUserKey())
                    {
                        this.UserkeyIsNull = false;
                    }
                    else
                    {
                        //this.lblMsg.Text = "--:--";
                        UpdateText(this.lblMsg, "--:--");

                        MessageBox.Show("Signed request is not empty or invalid.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        
                        //this.btnStart.Show();
                        //btnStart.BeginInvoke(delegate { btnStart.Show(); });
                        ShowHideControl(this.btnStart, true);

                        this.TheadOne.Abort();
                    }
                }
                
                Thread.Sleep(3000);
                this.ExportInformationUser();
                Thread.Sleep(10000);
                
                //this.lblMsg.Text = "Hacking";
                UpdateText(this.lblMsg, "Hacking");

                this.BienFistLike = 1;
                this.progressBar2.Value = 0;
                
                //this.lblThead2Percentage.Text = "0%";
                UpdateText(this.lblThead2Percentage, "0%");

                for (int j = 0; j < 5; j++)
                {
                    this.Komut2(this.BienFistLike.ToString());
                    this.BienFistLike += 140;
                    this.progressBar1.Value = 0;

                    //this.lblThead1Percentage.Text = "0%";
                    UpdateText(this.lblThead1Percentage, "0%");

                    for (int k = 0; k < 100; k++)
                    {
                        Thread.Sleep(100);
                        this.progressBar1.Value = k + 1;
                        
                        //this.lblThead1Percentage.Text = ((k + 1)).ToString() + "%";
                        UpdateText(this.lblThead1Percentage, ((k + 1)).ToString() + "%");

                        int num5 = ((j * 100) / 5) + ((k + 1) / 5);
                        this.progressBar2.Value = num5;
                        
                        //this.lblThead2Percentage.Text = num5.ToString() + "%";
                        UpdateText(this.lblThead2Percentage, num5.ToString() + "%");

                        int num6 = ((i * 100) / num) + (num5 / num);
                        this.progressBar3.Value = num6;
                        this.lblThead3Percentage.Text = num6.ToString() + "%";
                    }
                    this.progressBar2.Value = ((j + 1) * 100) / 5;

                    //this.lblThead2Percentage.Text = ((((j + 1) * 100) / 5)).ToString() + "%";
                    UpdateText(this.lblThead2Percentage, ((((j + 1) * 100) / 5)).ToString() + "%");
                }
                this.progressBar3.Value = ((i + 1) * 100) / num;
                this.lblThead3Percentage.Text = ((((i + 1) * 100) / num)).ToString() + "%";
                this.lblCount.Text = (i + 1).ToString();
            }
        }

        
        public void Komut2(string num)
        {            
            try
            {
                string str = this.KomutYolla(num);
                int index = str.IndexOf("bad command number: expected");
                if (index > -1)
                {
                    string s = null;
                    for (int i = index + 29; i < str.Length; i++)
                    {
                        if (str[i] == ',')
                        {
                            break;
                        }
                        s = s + str[i];
                    }
                    this.BienFistLike = int.Parse(s);
                    this.KomutYolla(s);
                }
                else if (str.IndexOf("bad user_key") > -1)
                {
                    this.UserkeyIsNull = true;
                }
                else if (str.IndexOf("KO") > -1)
                {
                    MessageBox.Show("Account is loadding!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    this.TheadOne.Abort();
                }
            }
            catch
            {
            }
        }

        public string KomutYolla(string num)
        {
            try
            {                
                string str = "{\"tries\":1,\"first_number\":";
                string str2 = ",\"publishActions\":0,\"flashVersion\":\"0.3.41\",\"ts\":";
                string str3 = ",\"commands\":[";
                string str4 = "{\"number\":";
                string str5 = ",\"args\":[";
                string str6 = "],\"cmd\":\"assist_receive\",\"time\":";
                string str7 = "],\"cmd\":\"buy_egg\",\"time\":";
                string str8 = "],\"cmd\":\"sell_egg\",\"time\":";
                string str9 = '}'.ToString();
                string str10 = "]}";

                //cheat gems
                string cmd_set_goals = "],\"cmd\":\"set_goals\",\"time\":";
                string cmd_complete_goal = "],\"cmd\":\"complete_goal\",\"time\":";

                string ab = "{\"ab\":[1,0,1,1,0";
                string str4_1 = "],\"number\":";
                string complete_collection = "],\"cmd\":\"complete_collection\",\"time\":";

                string reset_complete_collection = "],\"cmd\":\"reset_complete_collection\",\"time\":";

                int num3 = Timeto();
                int num4 = TimetoGioiHan();
                string str11 = null;
                int num5 = 140;
                if (this.rdFood.Checked)
                {
                    num5 = 140;//140=>7000
                    for (int i = 0; i < num5; i++)
                    {
                        if (i != 0)
                        {
                            str11 = str11 + ",";
                        }                       

                        //7000food
                        //object[] objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "1", str6, num3, str9 };        
                        object[] objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "18", str6, num3, str9 };                        
                        str11 = string.Concat(objArray);
                    }
                }
                else if (this.rdGold.Checked)
                {
                    lblMsg.Text = "Hacking gold";
                    num5 = 85; //75<=>37.5M
                    for (int j = 0; j < num5; j++)
                    {
                        if (j != 0)
                        {
                            str11 = str11 + ",";
                        }
                        object[] objArray2 = new object[] { str11, str4, ((j * 2) + 1).ToString(), str5, "12345678,1083", str7, num3, str9 };
                        str11 = string.Concat(objArray2) + ",";
                        object[] objArray3 = new object[8];
                        objArray3[0] = str11;
                        objArray3[1] = str4;
                        objArray3[2] = ((j * 2) + 2).ToString();
                        objArray3[3] = str5;
                        objArray3[4] = "12345678,1083";
                        objArray3[5] = str8;
                        objArray3[6] = num3;
                        objArray3[7] = str9;
                        str11 = string.Concat(objArray3);
                    }
                }
                else
                {

                    #region hack gems 1
                    for (int i=0;i<1;i++)
                    {
                        // 3gems (work 1 times)
                        if (i != 0)
                        {
                            str11 = str11 + ",";
                        }
                        //co the sai arg i+.
                        // no la so tong comand cua data json
                        object[] objArray0 = new object[] { str11, str4, (i + 1).ToString(), str5, "147,[0,1]", cmd_set_goals, num3, str9 };
                        str11 = string.Concat(objArray0);

                        str11 = str11 + ",";
                        object[] objArray1 = new object[] { str11, str4, (i + 2).ToString(), str5, "147", cmd_complete_goal, num3, str9 };
                        str11 = string.Concat(objArray1);

                        str11 = str11 + ",";
                        object[] objArray5 = new object[] { str11, str4, (i + 3).ToString(), str5, "134,[0,1]", cmd_set_goals, num3, str9 };

                        str11 = string.Concat(objArray5);
                        str11 = str11 + ",";
                        object[] objArray2 = new object[] { str11, str4, (i + 4).ToString(), str5, "134", cmd_complete_goal, num3, str9 };
                        str11 = string.Concat(objArray2);
                        
                        str11 = str11 + ",";
                        object[] objArray3 = new object[] { str11, str4, (i + 5).ToString(), str5, "148,[0,1]", cmd_set_goals, num3, str9 };
                        str11 = string.Concat(objArray3);

                        str11 = str11 + ",";
                        object[] objArray4 = new object[] { str11, str4, (i + 6).ToString(), str5, "148", cmd_complete_goal, num3, str9 };
                        str11 = string.Concat(objArray4);                       

                        str11 = str11 + ",";
                        object[] objArray6 = new object[] { str11, str4, (i + 7).ToString(), str5, "147,[0,1]", cmd_set_goals, num3, str9 };
                        str11 = string.Concat(objArray6);

                        str11 = str11 + ",";
                        object[] objArray9 = new object[] { str11, str4, (i + 8).ToString(), str5, "147", cmd_complete_goal, num3, str9 };
                        str11 = string.Concat(objArray9);

                        str11 = str11 + ",";
                        object[] objArray7 = new object[] { str11, str4, (i + 9).ToString(), str5, "145,[1,1]", cmd_set_goals, num3, str9 };
                        str11 = string.Concat(objArray7);

                        str11 = str11 + ",";
                        object[] objArray8 = new object[] { str11, str4, (i + 10).ToString(), str5, "145", cmd_complete_goal, num3, str9 };
                        str11 = string.Concat(objArray8);

                    ////    str11='{"args":[147,"[0,1]"],"number":'.$i.',"cmd":"set_goals","time":1372771201},';
                    ////    str11.='{"args":[147],"number":'.$i.',"cmd":"complete_goal","time":1372771201},';
                    ////    $hcx.='{"args":[134],"number":'.$i.',"cmd":"complete_goal","time":1372771201},';
                    ////    $hcx.='{"args":[148,"[0,1]"],"number":'.$i.',"cmd":"set_goals","time":1372771201},';
                    ////    $hcx.='{"args":[148],"number":'.$i.',"cmd":"complete_goal","time":1372771201},';
                    ////    $hcx.='{"args":[134,"[0,1]"],"number":'.$i.',"cmd":"set_goals","time":1372771201},';
                    ////    $hcx.='{"args":[147,"[0,1]"],"number":1,"cmd":"set_goals","time":1372771201},';
                    ////    $hcx.='{"args":[145,"[1,1]"],"number":1,"cmd":"set_goals","time":1372771201},';

                    ////    $hcx.='{"args":[145],"number":1,"cmd":"set_goals","time":1372771201},';

                    ////    $hcx.='{"args":[1],"number":'.$i.',"cmd":"assist_receive","time":1372771201},';
                    ////    }
                    ////    $hcx=substr($hcx,0,-1);
                    ////    $hc='{"commands":['.$hcx.']}';
                    ////    $hc=json_decode($hc,1);
                    ////    $num=1;
                    ////    for($i=0;$i<count($hc['commands']);$i++)
                    ////    {
                    ////    $hc['commands'][$i]['time']=time();
                    ////    }
                    }
                    #endregion hack gems 1

                    #region hack gems 2


                    //for (int i = 0; i < 5; i++)
                    //{
                    //    if (i != 0)
                    //    {
                    //        str11 = str11 + ",";
                    //    }
                        
                    //    //Page 1
                    //    object[]  objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "1", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + "," ;

                    //    //Page 2
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "2", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";

                    //    //Page 3
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "3", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";

                    //    //Page 4
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "4", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";
                        
                    //    //Page 5
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "5", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";
                        
                    //    //Page 6
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "6", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";
                        
                    //    //Page 7
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "7", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";
                        
                    //    //Page 8
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "8", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";
                       
                    //    //Page 9
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "9", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";
                        
                    //    //Page 10
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "10", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";
                        
                    //    //Page 11
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "11", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";

                    //    //Page 12
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "12", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";

                    //    //Page 13
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "13", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";

                    //    //Page 14
                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "14", complete_collection, num3, str9 };
                    //    str11 = string.Concat(objArray) + ",";

                    //    objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "", reset_complete_collection, num3, str9 };                        
                    //    str11 = string.Concat(objArray);
                    //}
                        
                        //$hcx .= '{"args":[],"number":' . $i . ',"cmd":"reset_complete_collection","time":1372771 201},'; $hcx = substr($hcx, 0, -1); $hc = '{"commands":[' . $hcx . ']}'; 

                        //$hc = json_decode($hc, 1); $num = 1; for ($i = 0; $i < count($hc['commands']); $i++) { $hc['commands'][$i]['time'] = time(); } } 

                    #endregion hack gems 2

                    #region Hack gems 3
                    //for (int i = 0; i < 500; i++)
                    //{
                    //    if (i != 0)
                    //    {
                    //        str11 = str11 + ",";
                    //    }

                    //    //7000food
                    //    //object[] objArray = new object[] { str11, str4, (i + 1).ToString(), str5, "1", str6, num3, str9 };        
                    //    object[] objArray = new object[] { str11, ab, str4_1, (i + 1).ToString(), str5, "1", str6, num3, str9 };
                    //    str11 = string.Concat(objArray);

                    //    //{"ab":[1,0,1,1,0],"number":1,"args":[1],"cmd":"complete_collection","time":1342439144},                        

                    //}
                    #endregion End Hack gems 3
                }
                string vao = null;
                if (num4 > num3)
                {
                    vao = string.Concat(new object[] { str, num, str2, num3, str3, str11, str10 });
                }
                //else
                //{
                //    MessageBox.Show("An error occurred or Dragon City fixed this bug", "Message", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                //    vao = string.Concat(new object[] { str, num, str2, TimeBackList(), str3, str11, str10 });
                //    this.TheadOne.Abort();
                //}
                string str14 = Encryption(vao).ToLower() + ';' + vao;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://dc-canvas.socialpointgames.com/dragoncity/web/srv/packet.php?USERID=" + this.FBID + "&user_key=" + this.UserKey + "&language=en");
                request.Method = "POST";
                request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ProtocolVersion = HttpVersion.Version11;
                request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                request.KeepAlive = false;
                request.Proxy = null;
                request.Credentials = CredentialCache.DefaultCredentials;
                request.Timeout = 300000;//0x493e0;
                request.ReadWriteTimeout = 300000;//0x493e0;
                string str16 = "id=" + this.FBID + "&data=" + str14;
                ServicePointManager.ServerCertificateValidationCallback = (RemoteCertificateValidationCallback)Delegate.Combine(ServicePointManager.ServerCertificateValidationCallback, new RemoteCertificateValidationCallback(frmMain.ValidateServerCertificate));
                StreamWriter writer = new StreamWriter(request.GetRequestStream());
                writer.Write(str16);
                writer.Close();
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());
                return reader.ReadToEnd();
            }
            catch
            {
                return null;
            }
        }

        public static string Encryption(string vao)
        {
            string s = "RGhXbiy4xEeDnSNX1oBG";
            string str3 = vao;
            string str4 = "";
            HMACSHA256 hmacsha = new HMACSHA256(Encoding.UTF8.GetBytes(s));
            hmacsha.ComputeHash(Encoding.UTF8.GetBytes(str3));
            foreach (byte num in hmacsha.Hash)
            {
                str4 = str4 + num.ToString("X2");
            }
            return str4;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            SignedRequest = txtSignedRequest.Text;
            flagStop = false;
            lblCount.Text = "0";
            NumRepeat = int.Parse(this.txtRepeat.Text);
            NumTimeDelay = int.Parse(this.txtDelay.Text);
            this.lblMsg.Text = "Connecting to get information";
            //this.SoLanVong = 0;
            this.progressBar3.Value = 0;
            this.btnStart.Hide();
            this.TheadOne = new Thread(new ThreadStart(this.FuntionRoot));
            this.TheadOne.Start();
            
        }

        private static int TimeBackList()
        {
            DateTime time = new DateTime(2016, 8, 10);
            TimeSpan span = (TimeSpan)(time - new DateTime(1970, 1, 1));
            return (int)span.TotalSeconds;
        }

        private static int Timeto()
        {
            TimeSpan span = (TimeSpan)(DateTime.UtcNow - new DateTime(1970, 1, 1));
            return (int)span.TotalSeconds;
        }

        private static int TimetoGioiHan()
        {
            DateTime time = new DateTime(2013, 8, 30);
            TimeSpan span = (TimeSpan)(time - new DateTime(1970, 1, 1));
            return (int)span.TotalSeconds;
        }

        private int FindFarm(string t, int typeFarm, int tim)
        {
            for (int i = tim; i < (t.Length - 3); i++)
            {
                if (typeFarm == 2)
                {
                    if (((t[i] == '[') && (t[i + 1] == '1')) && (t[i + 2] == '8'))
                    {
                        return i;
                    }
                }
                else if (typeFarm == 1)
                {
                    if (((t[i] == '[') && (t[i + 1] == '1')) && (t[i + 2] == '7'))
                    {
                        return i;
                    }
                }
                else if (typeFarm == 0)
                {
                    if (((t[i] == '[') && (t[i + 1] == '1')) && (t[i + 2] == '6'))
                    {
                        return i;
                    }
                }
                else if (((t[i] == '[') && (t[i + 1] == '2')) && (t[i + 2] == '8'))
                {
                    return i;
                }
            }
            return -1;
        }

        public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            return true;
        }

        public void ExportInformationUser()
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://dc-canvas.socialpointgames.com/dragoncity/web/srv/get_player_info.php?USERID=" + this.FBID + "&user_key=" + this.UserKey + "&language=en");
                request.Method = "POST";
                request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ProtocolVersion = HttpVersion.Version11;
                request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                request.KeepAlive = false;
                request.Proxy = null;
                request.Credentials = CredentialCache.DefaultCredentials;
                request.Timeout = 0x493e0;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                string str2 = new StreamReader(response.GetResponseStream()).ReadToEnd();
                int index = str2.IndexOf("\"name\":");
                string str3 = null;
                string str4 = null;
                string str5 = null;
                string str6 = null;
                if (index > -1)
                {
                    int num2 = index + 8;
                    while (num2 < str2.Length)
                    {
                        if (str2[num2] == '"')
                        {
                            break;
                        }
                        str3 = str3 + str2[num2];
                        num2++;
                    }
                    num2 += 9;
                    while (num2 < str2.Length)
                    {
                        if (str2[num2] == ',')
                        {
                            break;
                        }
                        str6 = str6 + str2[num2];
                        num2++;
                    }
                    num2 += 8;
                    while (num2 < str2.Length)
                    {
                        if (str2[num2] == ',')
                        {
                            break;
                        }
                        str5 = str5 + str2[num2];
                        num2++;
                    }
                    for (num2 += 8; num2 < str2.Length; num2++)
                    {
                        if (str2[num2] == ',')
                        {
                            break;
                        }
                        str4 = str4 + str2[num2];
                    }
                }
                
                this.lblName.Text = str3;
                this.lblGold.Text = str5; 
                this.lblFood.Text = str4; 
            }
            catch
            {
            }
        }


    }
}
